package org.starapp.plugins.freemarker;

import java.io.File;
import java.io.IOException;
import java.util.Locale;
import javax.servlet.ServletContext;
import freemarker.template.DefaultObjectWrapper;
import freemarker.template.ObjectWrapper;
import freemarker.template.TemplateExceptionHandler;

public class FreemarkerWeb extends Freemarker{

	ServletContext context;
	
	public FreemarkerWeb(String templateFolder,ServletContext context,Locale locale,String defaultEncoding) throws IOException{
		super(templateFolder,defaultEncoding,locale);
		this.context = context;
	}
	
	public void init() throws IOException{
		cfg.setDirectoryForTemplateLoading(new File(templateFolder));
		cfg.setObjectWrapper(new DefaultObjectWrapper());
		///WEB-INF/templates
        cfg.setServletContextForTemplateLoading(context, templateFolder);
        cfg.setTemplateUpdateDelay(0);
        cfg.setTemplateExceptionHandler(TemplateExceptionHandler.HTML_DEBUG_HANDLER);
        cfg.setObjectWrapper(ObjectWrapper.BEANS_WRAPPER);
        cfg.setDefaultEncoding(defaultEncoding);
        cfg.setOutputEncoding(defaultEncoding);
	}
}
